﻿using System.ComponentModel;
using Apps.IService;
using Apps.Model.Models;
using Apps.WebApi.Filter;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Apps.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IBaseService<SysMenu, int> _menuService;

        public MenuController(IBaseService<SysMenu, int> menuService)
        {
            _menuService = menuService;
        }

        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        [DisplayName("添加菜单")]
        public async Task AddMenu(SysMenu menu)
        {
            await _menuService.AddAsync(menu);
        }

        // GET: api/<MenuController>
        [HttpGet]
        [ServiceFilter(typeof(CustomActionFilter))]
        public async Task<IEnumerable<SysMenu>> Get()
        {
            return await _menuService.GetAllAsync();
        }

        // GET api/<MenuController>/5
        [HttpGet("{id}")]
        public async Task<SysMenu> Get(int id)
        {
            return await _menuService.GetByIdAsync(id);
        }

        // POST api/<MenuController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/<MenuController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<MenuController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {

        }
    }
}